#pragma once

#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif

#include <qobject.h>
#include <qserialport.h>
#include <qmutex.h>

class SerialPortWorker :
    public QObject
{
    Q_OBJECT

public:
    explicit SerialPortWorker(QObject* parent = nullptr);
    ~SerialPortWorker();

signals:
    void stateChanged(const bool& flag);
    void handleReadRusult(const QByteArray result);

public slots:
    void serialPortNameChanged(const QString& text);
    void serialInit();
    void serialOpen();
    void serialClose();

    void serialReadWork();
    void serialWriteWork(const QByteArray& data);

private:
    QMutex lock;
    QSerialPort* m_serialPort{ nullptr };
};

